package asia.doing.controller.admin;

import asia.doing.common.Result;
import asia.doing.entity.Comment;
import asia.doing.service.admin.ManageCommentService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController(value = "manageCommentController")
@RequestMapping("/manage/comment")
public class ManageCommentController {
    @Resource
    private ManageCommentService manageCommentService;

    @PostMapping("/add")
    public Result add(@RequestBody Comment comment){
        manageCommentService.add(comment);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Long id){
        manageCommentService.deleteById(id);
        return Result.success();
    }

    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Long> ids){
        manageCommentService.deleteBatch(ids);
        return Result.success();
    }

    @PutMapping("/update")
    public Result updateById(@RequestBody Comment comment){
        manageCommentService.updateById(comment);
        return Result.success();
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Long id){
        Comment comment = manageCommentService.selectById(id);
        return Result.success(comment);
    }

    @GetMapping("/selectAll")
    public Result selecatAll(Comment comment){
        List<Comment> lists = manageCommentService.selectAll(comment);
        return Result.success(lists);
    }

    @GetMapping("/selectCount")
    public Result selectCount(@RequestParam Long fid, @RequestParam String module){
        Long count = manageCommentService.selectCount(fid, module);
        return Result.success(count);
    }

    @GetMapping("/selectForUser")
    public Result selectForUser(Comment comment){
        List<Comment> list = manageCommentService.selectForUser(comment);
        return Result.success(list);
    }

    @GetMapping("/selectPage")
    public Result selectPage(Comment comment,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "2") Integer pageSize){
        PageInfo<Comment> page = manageCommentService.selectPage(comment, pageNum, pageSize);
        return Result.success(page);
    }
}
